<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit>
        <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <div class="table-operator">
              <a-button type="danger" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}</a-button>
              <a-button type="danger" @click="clearTasks">{{i18n('list.clearTaskBtn','清空任务')}}</a-button>
          </div>
          <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
        </div>
        <div slot="searchbar" btnalign="right"  v-if="fitSearch" @search="search" @cancel="cancel" @close="close">
          <a-form layout="vertical">
                <a-form-item :label="i18n('form.type','类型')">
                    <a-select v-model="queryParam.Q_TYPE__S_LK" :options="typeOptions" />
                </a-form-item>
                <a-form-item :label="i18n('form.relName','关联名称')">
                    <a-input :placeholder="i18n('form.relName','关联名称','input')" v-model="queryParam.Q_REL_NAME__S_LK"/>
                </a-form-item>
                <a-form-item :label="i18n('form.status','状态')">
                    <a-select v-model="queryParam.Q_STATUS__S_LK" :options="statusOptions" />
                </a-form-item>
          </a-form>
        </div>
        <rx-grid
                ref="table"
                :allowRowSelect="true"
                :multiSelect="true"
                :columns="columns"
                :defaultPageSize="10"
                url="/api-system/system/core/sysHttpTask/query"
                :queryParam="queryParam"
                data-field="result.data"
                :pageSizeOptions="['10','30','40']"
                id-field="id"
                @selectChange="onSelectChange"
        >
            <span slot="type" slot-scope="{text,record}">
                <a-tag :color="typeMap[text].color">
                    <span>{{ typeMap[text].text }}</span>
                </a-tag>
            </span>
            <span slot="status" slot-scope="{text,record}">
                <a-tag :color="statusMap[text].color">
                    <span>{{ statusMap[text].text }}</span>
                </a-tag>
            </span>
            <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                <span @click.stop="taskDetail(record)">{{i18n('list.viewLogBtn','查看日志')}}</span>
                <span @click.stop="invokeTask(record)">{{i18n('list.invokeBtn','重推')}}</span>
                <span @click.stop="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
            </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
  import SysHttpTaskApi from '@/api/system/core/sysHttpTask'
  import {BaseList, RxFit, RxGrid, Util} from "@lowcode/jpaas-common-lib";
  import SysHttpTaskLogList from "./SysHttpTaskLogList";
  export default {
      name: 'SysHttpTaskList',
      mixins: [BaseList],
      components: {
          RxFit
      },
      data() {
          return {
              columns: [
                  {
                      title: this.$ti18('rxList.index','序号'),
                      type: 'indexColumn',
                      width: 40,
                      dataIndex: 'serial',
                      scopedSlots: {customRender: 'serial'}
                  },
                  {title: this.i18n('form.type','类型'), dataIndex: 'type', width: 50, scopedSlots: {customRender: 'type'}},
                  {title: this.i18n('form.relName','关联名称'), dataIndex: 'relName', width: 150},
                  {title: this.i18n('form.status','状态'), dataIndex: 'status', width: 50, scopedSlots: {customRender: 'status'}},
                  {title: this.i18n('form.executeTimes','执行次数'), dataIndex: 'executeTimes', width: 80},
                  {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'},size:3}
              ],
              comment: this.i18n('list.comment','接口调用表'),
              widthHeight: ['800px', '600px'],
              fitSearch: false,
              typeMap: {
                  'webreq': { color: 'orange', text: this.i18n('typeMap.webreq','web请求定义') },
                  'interface': { color: 'blue', text: this.i18n('typeMap.interface','第三方接口') }
              },
              statusMap: {
                  'ok': { color: 'green', text: this.i18n('statusMap.success','执行成功')},
                  'fail': { color: 'red', text: this.i18n('statusMap.failure','执行失败') },
                  'failend': { color: 'red', text: this.i18n('statusMap.end','执行结束') }
              },
              typeOptions: [
                  {label: this.i18n('typeMap.webreq','web请求定义'), value: 'webreq'},
                  {label: this.i18n('typeMap.interface','第三方接口'), value: 'interface'}
              ],
              statusOptions: [
                  {label: this.i18n('statusMap.success','执行成功'), value: 'ok'},
                  {label: this.i18n('statusMap.failure','执行失败'), value: 'fail'},
                  {label: this.i18n('statusMap.end','执行结束'), value: 'failend'}
              ]
          }
      },
      methods: {
          i18n(name, text, key) {
              return this.$ti18(name, text, "SysHttpTask", key);
          },
          delById(ids) {
              return SysHttpTaskApi.del({ids: ids.join(',')});
          },
          getListByParams(parameter) {
              return SysHttpTaskApi.query(parameter)
          },
          clearTasks() {
              let self=this;
              this.$confirm({
                  title: self.$ti18('rxMsa.actionTips','操作提示'),
                  zIndex: 20000,
                  content: this.i18n('list.confirmTaskBtn','您确定需要清空任务吗？'),
                  okText: self.$ti18('rxForm.ackBtn','确认'),
                  cancelText: self.$ti18('rxForm.cancelBtn','取消'),
                  onOk() {
                      SysHttpTaskApi.clearAll().then(res => {
                          self.resetSearch();
                      });
                  }
              })
          },
          taskDetail(record){
              Util.open({
                  component: SysHttpTaskLogList,
                  curVm:this,
                  widthHeight:['900px','650px'],
                  title: this.i18n('taskLog.title','查看日志'),
                  data:{
                      taskId:record.pkId
                  }
              },function () {})
          },
          invokeTask(record){
              var self=this;
              this.$confirm({
                  title: self.$ti18('rxMsa.actionTips','操作提示'),
                  zIndex: 20000,
                  content: self.i18n('msa.invokeTips','您确定需要重推任务吗？'),
                  okText: self.$ti18('rxForm.ackBtn','确认'),
                  cancelText: self.$ti18('rxForm.cancelBtn','取消'),
                  onOk() {
                      SysHttpTaskApi.invokeTask(record.id).then(res=>{
                          self.resetSearch();
                      })
                  }
              })
          }
      }
  }
</script>
<style scoped>

</style>

